import sys

from framework.common.pt_logger import logger
sys.path.append('jobs/amazon')


class ModuleLoader(object):
    def __init__(self, module_name, **kwargs):
        self.module_name = module_name
        self.args = kwargs

    def load(self):
        __import__(self.module_name)
        spider_lib = sys.modules[self.module_name]
        for item in self.args.items():
            spider_lib.__dict__[item[0]] = item[1]
            logger.info("Parameter pair key: %s, value: %s" % (item[0], item[1]))
        return spider_lib


if __name__ == "__main__":
    loader = ModuleLoader("initiators.coreProducts_initiator", spider_name="CoreProductsBestSellers")
    spider_lib = loader.load()
    print("done")
